// StringTest.m -- test out the String class

#import <appkit/appkit.h>
#import "DAYString.m"
#import <stdio.h>

void main()
{
	id string1, string2, string3, string4, string5, string6, string7;
	string1 = [[[DAYString alloc] init] setStringValue:"The first string."];
	string2 = [[DAYString alloc] initString:"01234567890123456789"];
	printf("string1 = \"%s\", length = %d.\n", [string1 stringValue],
			[string1 length]);
	printf("string2 = \"%s\", length = %d.\n", [string2 stringValue],
			[string2 length]);
	string3 = [string1 copy];
	[string3 concatenate:string2];
	printf("String1 + String2 = \"%s\", length = %d.\n",
			[string3 stringValue], [string3 length]);
	printf("String1 = \"%s\", length = %d.\n", [string1 stringValue],
			[string1 length]);
	[string3 free];
	printf("string1!=string1: %d, string1!=string2: %d\n",
			[string1 compareTo:string1], [string1 compareTo:string2]);
	string3 = [string2 left:5];
	string4 = [string2 right:5];
	string5 = [string2 midFrom:5 to:10];
	string6 = [string2 midFrom:6 length:5];
	printf("left5 = %s right5 = %s mid5to10 = %s mid6len5 = %s\n",
			[string3 stringValue], [string4 stringValue],
			[string5 stringValue], [string6 stringValue]);
	[string3 free]; [string4 free]; [string5 free]; [string6 free];
	string5 = [[DAYString alloc] initString:"first"];
	string3 = [string1 subStringLeft:string5];
	string4 = [string1 subStringRight:string5];
	printf("Substrings from string1 and \"first\"...Left:\"%s\" Right:\"%s\"\n",
			[string3 stringValue], [string4 stringValue]);
	[string5 setStringValue:"don:*:23:21:Don Yacktman:/LocalLibrary/Users/don:/bin/csh"];
	printf("Extract parts from \"%s\" delimiting with ':':\n",
			[string5 stringValue]);
	printf("    Part    #3 is \"%s\"\n",
			[[string5 extractPart:3 useAsDelimiter:':'] stringValue]);
	printf("    Part   #10 is \"%s\"\n",
			[[string5 extractPart:10 useAsDelimiter:':'] stringValue]);
	printf("Return was %s.\n", [string5 extractPart:10 useAsDelimiter:':'] ? "empty object" : "nil");
	printf("    First part is \"%s\"\n",
			[[string5 extractPart:DAY_FIRST useAsDelimiter:':'] stringValue]);
	printf("    Last  part is \"%s\"\n",
			[[string5 extractPart:DAY_LAST useAsDelimiter:':'] stringValue]);
	[string5 setStringValue:"/Net/darth/Users/don/Projects/daymisckit_proj/daymisckit-1/DAYString.m"];
	printf("Given:        %s\n", [string5 stringValue]);
	printf("    Path is:  %s\n", [[string5 pathName] stringValue]);
	printf("Filename is:  %s\n", [[string5 fileName] stringValue]);

	//Carl's tests...
	string7 = [DAYString newWithString:"   Hello, how are you?   "];
	printf("Carl's string: \"%s\", length = %d\n",
			[string7 stringValue], [string7 length]);
	printf("Numwords: %d\n",[string7 numWords]);
	printf("3rd word: \"%s\"\n",[[string7 wordNum:3] stringValue]);
	printf("trimmed: \"%s\"\n",[[string7 trimSpaces] stringValue]);
		printf("Numwords: %d\n",[string7 numWords]);
	printf("Reversed: \"%s\"\n",[[string7 reverse] stringValue]);
	printf("Reversed again: \"%s\"\n",[[string7 reverse] stringValue]);
	printf("ToUpper:  \"%s\"\n",[[string7 toUpper] stringValue]);
	printf("ToLower:  \"%s\"\n",[[string7 toLower] stringValue]);
	printf("Inserting \"Oh! \" at 0:  \"%s\"\n",
			[[string7 insert:"Oh! " at:0] stringValue]);
	printf("Char at 0: '%c'\n",[string7 charAt:0]);
	printf("ReplaceFrom 0to2 with \"YOHO!\":  \"%s\"\n",
			[[string7 replaceFrom:0 to:2 with:"YOHO!"] stringValue]);
	printf("spotOf 'o': %d\n",[string7 spotOf:'o']);
	printf("spotOf 'o' nocase: %d\n",
			[string7 spotOf:'o' caseSensitive:NO]);
	printf("rspotOf 'O': %d\n",[string7 rspotOf:'O']);
	printf("rspotOf 'O' nocase: %d\n",
			[string7 rspotOf:'O' caseSensitive:NO]);
	printf("10th rspotOf 'O': %d\n",[string7 rspotOf:'O' occurenceNum:10]);
	printf("replace \"YOHO!\" with \"My!\": \"%s\"\n",
			[[string7 replace:"YOHO!" with:"My!"] stringValue]);
	printf("String now is \"%s\"\n",
			[[string7 setStringValue:"  Hello,   I    am  fine today.  Right?  "]
			stringValue]);
	printf("Squashed: \"%s\"\n",[[string7 squashSpaces] stringValue]);
	printf("endcmp \"Right?\": %d\n",[string7 endcmp:"Right?"]);
	printf("endcasecmp \"RIGHT?\": %d\n",[string7 endcasecmp:"RIGHT?"]);
	printf("endcmp \"RIGHT?\": %d\n",[string7 endcmp:"RIGHT?"]);
	printf("endcasecmp n:3 \"nacHT?\": %d\n",
			[string7 endcasecmp:"nacHT?" n:3]);
	printf("replaceCharAt:0 with 'J': \"%s\"\n",
			[[string7 replaceCharAt:0 with:'J'] stringValue]);
	printf("insertChar 'a' at 1: \"%s\"\n",
			[[string7 insertChar:'a' at:1] stringValue]);
	[string3 free]; [string4 free]; [string5 free];
	[string1 free]; [string2 free]; [string7 free];
	exit(0);
}
